﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

using System.Text;
using OpenGado.Business.Exceptions;
using OpenGado.DATA;
using OpenGado.DATA.Entities;

namespace OpenGado.Business
{
    public class ProjectBusiness
    {
        /// <summary>
        /// Performs Business logic checks and saves the Project object via the DAO layer
        /// </summary>
        /// <param name="project"></param>
        public void SaveProject(Project project)
        {
            // check if all values are in place then do the save

            if (String.IsNullOrEmpty(project.Coordinator))
            {
                throw new InvalidPropertyValueException("Project coordinator value cannot be null");
                return;

            }
            else if (String.IsNullOrEmpty(project.Name))
            {
                throw new InvalidPropertyValueException("Project name cannot be empty");
                return;
            }


            try
            {
                ProjectDataControl.Instance.Save(project);
               
            }
            catch (Exception exception)
            {
                throw new DbOperationException("Failed to Save project object", exception);
            }


        }
        /// <summary>
        /// Delete a Project
        /// </summary>
        /// <param name="project"></param>
        public void DeleteProject (Project project)
        {
          
            ProjectDataControl.Instance.Delete(project);
        }

        /// <summary>
        /// Fetch List of projects
        /// </summary>
        /// <returns></returns>
        public IList<Project> ProjectList()
        {

            return ProjectDataControl.Instance.GetAllProjects();
        }

        /// <summary>
        /// Fetch project object
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        public  Project GetProject(int projectId)
        {
            
            return ProjectDataControl.Instance.GetById(projectId);
        }


    }
}
